@extends('layout.page')
@section('title','奖池管理 - 详情')
@section('stylesheet')
    <link href="/css/ceb/gift-packs.css?v=4.1.0" rel="stylesheet">
@endsection

@section('static-page')
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>奖池管理 <small>详情</small></h5>
            </div>
            <div class="ibox-content">
                <form method="post" action="" class="form-horizontal">
                    {{csrf_field()}}
                    <input type="hidden" name="info[id]" readonly value="{{$info->id}}"/>
                    <div class="form-group  ">
                        <label class="col-sm-2 control-label">奖池名称：</label>
                        <div class="col-sm-6">
                            <div class="row">
                                <div class="col-md-8">
                                    <input type="text" name="info[name]" readonly value="{{$info->name}}"
                                           placeholder="奖池名称" class="form-control">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group ">
                        <label class="col-sm-2 control-label">有效时间：</label>
                        <div class="col-sm-2 m-b-xs">
                            <div class="input-group">
                                <input placeholder="开始日期" value="{{date('Y-m-d',$info->start_time)}}" class="form-control layer-date" readonly id="start">
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-xs">
                            <div class="input-group">
                                <input placeholder="结束日期" readonly  value="{{date('Y-m-d',$info->end_time)}}" class="form-control layer-date" id="end">
                            </div>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">审核：</label>

                        <div class="col-sm-2">
                            <select class="form-control m-b" readonly name="info[status]">
                                @foreach($status as $key=>$val)
                                    <option value="{{$val['id']}}" @if($info->status ==$val['id'] ) selected @endif>
                                        {{$val['name']}}
                                    </option>
                                @endforeach
                            </select>
                            <span class="help-block m-b-none">{{$errors->first('info.type')}}</span>
                        </div>
                    </div>
                    <div class="ibox-title">
                        <h5>奖池<small></small></h5>
                    </div>
                    <div class="row">
                        <div class="gift-packs-container">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                <tr>
                                    <th> </th>
                                    <th>券名称</th>
                                    <th>面值</th>
                                    <th>起投金额</th>
                                    <th>起投期限</th>
                                    <th>有效期截止</th>
                                    <th>有效天数</th>
                                </tr>
                                </tr>
                                </thead>
                                <tbody class="_table-quan-container">
                                <?php $array_items = json_decode($info->items,true)?>
                                @foreach($array_items['red_packet_list'] as $key => $val)
                                    <tr class="gradeA">
                                        <td>红包</td>
                                        <td><input  class="form-control" value="{{$val['name']}}" readonly name="HB[{{$key}}][name]" ></td>
                                        <td><input  class="form-control" value="{{$val['value']}}" readonly name="HB[{{$key}}][value]"></td>
                                        <td><input  class="form-control" value="{{$val['min_investment']}}" readonly name="HB[{{$key}}][min_investment]"></td>
                                        <td><input  class="form-control" value="{{$val['duration']}}" readonly name="HB[{{$key}}][duration]"></td>
                                        <td><input  class="form-control" value="{{$val['expire_date']}}" readonly name="HB[{{$key}}][expire_date]"></td>
                                        <td><input  class="form-control" value="{{$val['effective_duration']}}" readonly name="HB[{{$key}}][effective_duration]"></td>
                                        <input  class="form-control" type="hidden" value="{{$val['expire_type']}}"  readonly name="HB[{{$key}}][expire_type]">
                                    </tr>
                                @endforeach
                                @foreach($array_items['cash_voucher_list'] as $key => $val)
                                    <tr class="gradeA">
                                        <td>现金券</td>
                                        <td><input  class="form-control" value="{{$val['name']}}" readonly name="XJQ[{{$key}}][name]" ></td>
                                        <td><input  class="form-control" value="{{$val['value']}}" readonly name="XJQ[{{$key}}][value]"></td>
                                        <td><input  class="form-control" value="{{$val['min_investment']}}" readonly name="XJQ[{{$key}}][min_investment]"></td>
                                        <td><input  class="form-control" value="{{$val['duration']}}" readonly name="XJQ[{{$key}}][duration]"></td>
                                        <td><input  class="form-control" value="{{$val['expire_date']}}" readonly name="XJQ[{{$key}}][expire_date]"></td>
                                        <td><input  class="form-control" value="{{$val['effective_duration']}}" readonly name="XJQ[{{$key}}][effective_duration]"></td>
                                        <input  class="form-control" type="hidden" value="{{$val['expire_type']}}"  readonly name="XJQ[{{$key}}][expire_type]">
                                    </tr>
                                @endforeach
                                @foreach($array_items['rate_increment_voucher_list'] as $key => $val)
                                    <tr class="gradeA">
                                        <td>加息券</td>
                                        <td><input  class="form-control" value="{{$val['name']}}" readonly name="JXQ[{{$key}}][name]" ></td>
                                        <td><input  class="form-control" value="{{$val['value']}}" readonly name="JXQ[{{$key}}][value]"></td>
                                        <td><input  class="form-control" value="{{$val['min_investment']}}" readonly name="JXQ[{{$key}}][min_investment]"></td>
                                        <td><input  class="form-control" value="{{$val['duration']}}" readonly name="JXQ[{{$key}}][duration]"></td>
                                        <td><input  class="form-control" value="{{$val['expire_date']}}" readonly name="JXQ[{{$key}}][expire_date]"></td>
                                        <td><input  class="form-control" value="{{$val['effective_duration']}}" readonly name="JXQ[{{$key}}][effective_duration]"></td>
                                        <input  class="form-control" type="hidden" value="{{$val['expire_type']}}"  readonly name="JXQ[{{$key}}][expire_type]">
                                    </tr>
                                @endforeach

                                </tbody>
                                <tfoot>
                                <tr>
                                    <th> </th>
                                    <th>券名称</th>
                                    <th>面值</th>
                                    <th>起投金额</th>
                                    <th>起投期限</th>
                                    <th>有效期截止</th>
                                    <th>有效天数</th>
                                </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>


                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <a href="javascript:void(0);" onclick="window.history.back()">
                                <button class="btn btn-white" type="button">返回</button>
                            </a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('javascript')

    <script>
        $(document).ready(function(){
            //礼包有效时间
            var start = {
                elem: '#start',
                format: 'YYYY-MM-DD',
                /*  min: laydate.now(),*/
                max: '2099-06-16 23:59:59',
                istime: true,
                istoday: false,
                choose: function (datas) {
                    end.min = datas; //结束日选好后，重置开始日的最大日期
                }
            };
            var end = {
                elem: '#end',
                format: 'YYYY-MM-DD',
                /*  min: laydate.now(),*/
                max: '2099-06-16 23:59:59',
                istime: true,
                istoday: false,
                choose: function (datas) {
                    start.max = datas; //结束日选好后，重置开始日的最大日期
                }
            };
            $("#start").click(function () {
                laydate(start);
            });
            $("#end").click(function () {
                laydate(end);
            });




            var ex_int = /^\d+$/;
            var count_tr = $('._table-quan-container').children('tr').length

            //添加红包
            $("#btn-add-hb").click(function () {
                var hb={};
                //券名
                if($('#input-hb-name').val().length==0){
                    $('#input-hb-name').next().html('券名不能为空');
                    $('#input-hb-name').parents('.form-group').addClass('has-error');
                    return false;
                }
                $('#input-hb-name').next().html('');
                $('#input-hb-name').parents('.form-group').removeClass('has-error');
                hb['name'] = $("#input-hb-name").val();

                //红包面值
                if($('#input-hb-val').val().length==0){
                    $('#input-hb-val').next().html('券名不能为空');
                    $('#input-hb-val').parents('.form-group').addClass('has-error');
                    return false;
                }

                //红包面值
                if(isNaN($('#input-hb-val').val())){
                    $('#input-hb-val').next().html('值必须为数子');
                    $('#input-hb-val').parents('.form-group').addClass('has-error');
                    return false;
                }
                $('#input-hb-val').next().html('');
                $('#input-hb-val').parents('.form-group').removeClass('has-error');
                hb['val'] = $("#input-hb-val").val();

                var _url= '/js/admin/ceb/gift-packs-tr-template.html?v=322';
                $.get( _url).success(function(data){
                    var _strhtml=data;
                    var reg_type=/TYPE/g;
                    _strhtml=_strhtml.replace(reg_type,'HB');
                    var reg_type=/NUMBER/g;
                    _strhtml=_strhtml.replace(reg_type,count_tr);
                    var reg_type=/TITLE/g;
                    _strhtml=_strhtml.replace(reg_type,'红包');
                    $("._table-quan-container").prepend(_strhtml);

                    $("input[name='HB["+count_tr+"][name]']").val(hb['name']);
                    $("input[name='HB["+count_tr+"][val]']").val(hb['val']);
                    count_tr++;
                    //重绑 移除事件
                    $(".delete-remove").click(function () {
                        $(this).parents('tr').remove();
                    });
                    //关闭窗口
                    $("._close-modal").click();

                });

            });
            //添加加息券
            $("#btn-add-jx").click(function () {

                var jxq={};
                //券名
                if($('#input-jx-name').val().length==0){
                    $('#input-jx-name').next().html('券名不能为空');
                    $('#input-jx-name').parents('.form-group').addClass('has-error');
                    return false;
                }
                $('#input-jx-name').next().html('');
                $('#input-jx-name').parents('.form-group').removeClass('has-error');
                //加息值
                if($("#input-jx-val").val().length==0){
                    $('#input-jx-val').next().html('加息值不能为空');
                    $('#input-jx-val').parents('.form-group').addClass('has-error');
                    return false;
                }
                if(isNaN($("#input-jx-val").val())){
                    $('#input-jx-val').next().html('加息值必须为数字');
                    $('#input-jx-val').parents('.form-group').addClass('has-error');
                    return false;
                }
                $('#input-jx-val').next().html('');
                $('#input-jx-val').parents('.form-group').removeClass('has-error');

                //起投金额
                if($("#input-jx-atleast").val().length>0 && !ex_int.test($("#input-jx-atleast").val())){
                    $('#input-jx-atleast').next().html('起投金额必须为整数');
                    $('#input-jx-atleast').parents('.form-group').addClass('has-error');
                    return false;
                }
                $('#input-jx-atleast').next().html('');
                $('#input-jx-atleast').parents('.form-group').removeClass('has-error');

                //期限
                if($("#input-jx-atleastDay").val().length>0 && !ex_int.test($("#input-jx-atleastDay").val())){
                    $('#input-jx-atleastDay').next().html('期限必须为整数');
                    $('#input-jx-atleastDay').parents('.form-group').addClass('has-error');
                    return false;
                }
                $('#input-jx-atleastDay').next().html('');
                $('#input-jx-atleastDay').parents('.form-group').removeClass('has-error');

                var effectiveId = $("input[name='limitType']").val();
                if(effectiveId =='input-jx-effectiveday' && $("#"+effectiveId).val().length>0 ){
                    if(!ex_int.test($("#"+effectiveId).val())){
                        $("#"+effectiveId).next().html('有效天数必须为整数');
                        $("#"+effectiveId).parents('.form-group').addClass('has-error');
                        return false;
                    }
                }
                $("#"+effectiveId).next().html('');
                $("#"+effectiveId).parents('.form-group').removeClass('has-error');

                var _url= '/js/admin/ceb/gift-packs-tr-template.html?v=322';
                $.get( _url).success(function(data){
                    var _strhtml=data;
                    var reg_type=/TYPE/g;
                    _strhtml=_strhtml.replace(reg_type,'JXQ');
                    var reg_type=/NUMBER/g;
                    _strhtml=_strhtml.replace(reg_type,count_tr);
                    var reg_type=/TITLE/g;
                    _strhtml=_strhtml.replace(reg_type,'加息券');
                    $("._table-quan-container").prepend(_strhtml);

                    $("input[name='JXQ["+count_tr+"][name]']").val($('#input-jx-name').val());
                    $("input[name='JXQ["+count_tr+"][val]']").val($('#input-jx-val').val());
                    $("input[name='JXQ["+count_tr+"][atleast]']").val($('#input-jx-atleast').val());
                    $("input[name='JXQ["+count_tr+"][atleastDay]']").val($("#input-jx-atleastDay").val());
                    $("input[name='JXQ["+count_tr+"][effectiveType]']").val($("input[name='limitType']:checked").data('effectivtype'));
                    if($("input[name='limitType']:checked").data('effectivtype')==1){
                        $("input[name='JXQ["+count_tr+"][effective]']").val($("#input-jx-effectiveday").val());
                    }
                    else{
                        $("input[name='JXQ["+count_tr+"][effective]']").val($("#input-jx-effectivedate").val());
                    }
                    console.log($("input[name='limitType']:checked").data('effectivtype'));
                    count_tr++;
                    //重绑 移除事件
                    $(".delete-remove").click(function () {
                        $(this).parents('tr').remove();
                    });
                    //关闭窗口
                    $("._close-modal").click();

                });

            });

            //添加现金券
            $("#btn-add-xj").click(function () {
                var xjq={};
                if($("#input-xj-name").val().length==0){
                    $('#input-xj-name').next().html('券名不能为空');
                    $('#input-xj-name').parents('.form-group').addClass('has-error');
                    return false;
                }
                $('#input-xj-name').next().html('');
                $('#input-xj-name').parents('.form-group').removeClass('has-error');
                xjq['name'] = $("#input-xj-name").val();

                if( $("#input-xj-val").val().length == 0 || isNaN($('#input-xj-val').val())){
                    $('#input-xj-val').next().html('值必为数字');
                    $('#input-xj-val').parents('.form-group').addClass('has-error');
                    return false;
                }
                $('#input-xj-val').next().html('');
                $('#input-xj-val').parents('.form-group').removeClass('has-error');
                xjq['val'] =  $('#input-xj-val').val();


                if($("#input-xj-atleast").val().length>0 && !ex_int.test($("#input-xj-atleast").val())){
                    $("#input-xj-atleast").next().html('值必须为数字');
                    $("#input-xj-atleast").parents('.form-group').addClass('has-error');
                    return false;
                }
                $("#input-xj-atleast").next().html('');
                $("#input-xj-atleast").parents('.form-group').removeClass('has-error');
                xjq['atleast'] =  $("#input-xj-atleast").val();

                if($("#input-xj-atleastDay").val().length>0 && !ex_int.test($("#input-xj-atleastDay").val())){
                    $("#input-xj-atleastDay").next().html('值必须为数字');
                    $("#input-xj-atleastDay").parents('.form-group').addClass('has-error');
                    return false;
                }
                $("#input-xj-atleastDay").next().html('');
                $("#input-xj-atleastDay").parents('.form-group').removeClass('has-error');
                xjq['atleastDay'] =  $("#input-xj-atleastDay").val();

                xjq['limitType'] = $("input[name='xjq-limitype']:checked").val();
                if(xjq['limitType']==1){
                    xjq['effective'] = $("#input-xj-effectiveday").val();
                    if(xjq['effective'].length>0 && !ex_int.test(xjq['effective'])){
                        $("#input-xj-effectiveday").next().html('值必须为数字');
                        $("#input-xj-effectiveday").parents('.form-group').addClass('has-error');
                        return false;
                    }
                }
                else{
                    xjq['effective'] = $("#input-xj-effectivedate").val();
                }

                var _url= '/js/admin/ceb/gift-packs-tr-template.html?v=322';
                $.get( _url).success(function(data){
                    var _strhtml=data;
                    var reg_type=/TYPE/g;
                    _strhtml=_strhtml.replace(reg_type,'XJQ');
                    var reg_type=/NUMBER/g;
                    _strhtml=_strhtml.replace(reg_type,count_tr);
                    var reg_type=/TITLE/g;
                    _strhtml=_strhtml.replace(reg_type,'现金券');
                    $("._table-quan-container").prepend(_strhtml);

                    $("input[name='XJQ["+count_tr+"][name]']").val(xjq['name']);
                    $("input[name='XJQ["+count_tr+"][val]']").val(xjq['val']);
                    $("input[name='XJQ["+count_tr+"][atleast]']").val(xjq['atleast']);
                    $("input[name='XJQ["+count_tr+"][atleastDay]']").val(xjq['atleastDay']);
                    $("input[name='XJQ["+count_tr+"][effectiveType]']").val(xjq['limitType']);
                    $("input[name='XJQ["+count_tr+"][effective]']").val(xjq['effective']);
                    console.log($("input[name='limitType']:checked").data('effectivtype'));
                    count_tr++;
                    //重绑 移除事件
                    $(".delete-remove").click(function () {
                        $(this).parents('tr').remove();
                    });
                    //关闭窗口
                    $("._close-modal").click();

                });


            });

            //加息chebox 点击
            $("input[name='limitType']").change(function () {
                var docment = $("#"+$(this).val()).parents('.form-group');
                docment.show().siblings().hide();
            });
            //现金券chebox 点击
            $("input[name='xjq-limitype']").change(function () {
                var docment = $("#"+$(this).data('val')).parents('.form-group');
                docment.show().siblings().hide();
            });

            //移除事件
            $(".delete-remove").click(function () {
                $(this).parents('tr').remove();
            });


            //加息时间控件
            var time_modle_jx = {
                elem: '#input-jx-effectivedate',
                format: 'YYYY-MM-DD',
                min: laydate.now(),
                max: '2099-06-16 23:59:59',
                istime: true,
                istoday: false,
                choose: function (datas) {
                    //start.max = datas; //结束日选好后，重置开始日的最大日期
                }
            };
            $("#input-jx-effectivedate").click(function () {
                laydate(time_modle_jx);
            });

            //现金券时间控件
            var time_modle_xj = {
                elem: '#input-xj-effectivedate',
                format: 'YYYY-MM-DD',
                min: laydate.now(),
                max: '2099-06-16 23:59:59',
                istime: true,
                istoday: false,
                choose: function (datas) {
                    //start.max = datas; //结束日选好后，重置开始日的最大日期
                }
            };
            $("#input-xj-effectivedate").click(function () {
                laydate(time_modle_xj);
            });

        });
    </script>
@endsection
